<?php session_start();

if($_SESSION['ultimaAcaoMinhaConta'] != "ALTERARCADASTRO") {
    unset($_SESSION["menssagemErro"]);
}

$menssagemErro = $_SESSION["menssagemErro"];
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="/Esquina_da_TI/default.css" rel="stylesheet" type="text/css" media="screen" />
        <script type="text/javascript" src="formulario.js"></script>
         <script type="text/javascript" src="../js/calendar1.js"></script>
        <title>Alteração de Cadastro</title>
    </head>
    <body>
        <center>
            <h1>Alteração de Cadastro</h1>
            <form id="formularioEdicaoUsuario" name="formularioEdicaoUsuario" method="POST" action="ControleEdicaoUsuario.php" enctype='multipart/form-data'>
                <input type="hidden" id="action" name="action">
                <table  cellspacing="1" cellpadding="1">
                    <?php
                    require_once($_SERVER["DOCUMENT_ROOT"] . '/Esquina_da_TI/ClassesBasicas/Moderador.php');
                    require_once($_SERVER["DOCUMENT_ROOT"] . '/Esquina_da_TI/ClassesBasicas/Editor.php');
                    require_once('Fachada.php');

                    $usuario = null;
                    $fachada = new Fachada();

                    $login = $_SESSION['login'];

                    $usuario = $fachada->localizarUsuario($codigo, $nome, $login);
                    if($usuario != null) {
                        $_SESSION["menssagemErro"] = "";
                        exibirUsuario($usuario);
                    }else {
                        $_SESSION["menssagemErro"] = "Não Foi Possivel Localizar o Usuario Com o Nome/Login Informados";
                        $_SESSION['ultimaAcaoMinhaConta'] != "LOCALIZARUSUARIO";
                        echo "<meta HTTP-EQUIV='Refresh' CONTENT='0;URL=/Esquina_da_TI/GUI/MinhaConta.php'>";
                    }


                    function exibirUsuario($usuario) {
                        echo "<tr><td class='head' colspan='2'>". $usuario->getPrivilegio()."</td></tr>";
                        echo "<tr><th>Codigo:</th><td>";
                        echo "<input type='text' name='cod' disabled='true' size='10' value='". $usuario->getCodUsuario() . "'>";
                        echo "<input type='hidden' name='codigo' value='". $usuario->getCodUsuario() . "'>";
                        echo "</td></tr><tr>";
                        echo "<th>Nome:</th><td>";
                        echo "<input type='text' name='nome' size='50' value='". $usuario->getNome() ."'>";
                        echo "</td></tr><tr>";
                        echo "<th>Email:</th><td>";
                        echo "<input type='text' name='email' size='30' value='". $usuario->getEmail() . "'>";
                        echo "</td></tr><tr>";
                        echo "<th>Login:</th><td>";
                        echo "<input type='text' name='login' size='30' value='". $usuario->getLogin() . "'>";
                        echo "</td></tr>";
                        echo "<input type='hidden' name='senha' size='30' value='". $usuario->getSenha() . "'>";
                        echo "<input type='hidden' name='confirmaSenha' size='30' value='". $usuario->getSenha() . "'>";
                        echo "<th>Privilegio:</th><td>";
                        echo "<input type='hidden' name='privilegio' value='".$usuario->getPrivilegio(). "'>";//pegando o privilegio do usuario

                        if($usuario->getPrivilegio() == Privilegio::EDITOR) {
                            echo "<input type='text' name='tipoWebMaster' disabled='false' value='EDITOR'>&nbsp;&nbsp;";
                        }else if($usuario->getPrivilegio() == Privilegio::MODERADOR) {
                                echo "<input type='text' name='tipoWebMaster' disabled='false' value='MODERADOR'>&nbsp;&nbsp;";
                            }else if($usuario->getPrivilegio() == Privilegio::WEBMASTER) {
                                    echo "<input type='text' name='tipoWebMaster' disabled='false' value='WEBMASTER'>&nbsp;&nbsp;";
                                }else if($usuario->getPrivilegio() == Privilegio::CLIENTE) {
                                        echo "<input type='text' name='tipoWebMaster' disabled='false' value='CLIENTE'>&nbsp;&nbsp;";
                                    }else {
                                        echo "<input type='text' name='tipoWebMaster' disabled='false' value='USUÁRIO'>&nbsp;&nbsp;";
                                    }


                        echo "</td></tr><tr>";
                        if ($usuario->getPrivilegio() == Privilegio::EDITOR || $usuario->getPrivilegio()== Privilegio::MODERADOR || $usuario->getPrivilegio()== Privilegio::USUARIO || $usuario->getPrivilegio()== Privilegio::WEBMASTER){

                        
                        
                             echo "<tr>
                                     <th>Data de Nascimento:&nbsp;&nbsp;</th>
                                     <td>
                                     <input type='Text' name='dataNascimento' id='dataNascimento' size='8' value='". $usuario->getDataNascimento() . "' readonly>
                                     <a href='javascript:cal1.popup();'><img alt='' src='../images/cal.gif' width='16' height='16' border='0' ></a><br>
                                     </td>
                                     </tr>
                                     <tr>
                                     <th>Foto:&nbsp;&nbsp;</th>
                                     <td><input type='file' id='foto' name='foto' size='15' onblur='comprova_extensao(this.form.foto.value)'>&nbsp;<label id='campo_foto'/><input type=hidden name=validacaoFoto id='validacaoFoto' value=1>
                                     <br><font size='1'>Formatos Permitidos </font><font color='red' size='1'>(JPEG,GIF,BMP,TIFF,PNG)</font>
                                     </td><td><img src='". $usuario->getFoto(). "' width='100' height='100' alt='Sem foto'/></td>
                                     </tr>";
                        }
                        if($usuario->getPrivilegio() == Privilegio::CLIENTE) {
                            if ($usuario->getCnpj()=="") {
                                echo "</td></tr><tr>";
                                echo "<th>Cpf:</th><td>";
                                echo "<input type='text' name='cpf' size='11' value='". $usuario->getCpf() . "'>";
                                echo "</td></tr>";
                                echo "<tr>
                                     <th>Data de Nascimento:&nbsp;&nbsp;</th>
                                     <td>
                                     <input type='Text' name='dataNascimento' id='dataNascimento' size='8' value='". $usuario->getDataNascimento() . "' readonly>
                                     <a href='javascript:cal1.popup();'><img alt='' src='../images/cal.gif' width='16' height='16' border='0' ></a><br>
                                     </td>
                                     </tr>
                                     <tr>
                                     <th>Foto:&nbsp;&nbsp;</th>
                                     <td><input type='file' id='foto' name='foto' size='15' onblur='comprova_extensao(this.form.foto.value)'>&nbsp;<label id='campo_foto'/><input type=hidden name=validacaoFoto id='validacaoFoto' value=1>
                                     <br><font size='1'>Formatos Permitidos </font><font color='red' size='1'>(JPEG,GIF,BMP,TIFF,PNG)</font>
                                     </td><td><img src='". $usuario->getFoto(). "' width='100' height='100' alt='Sem foto'/></td>
                                     </tr>";

                            }
                            else if ($usuario->getCpf()=="") {
                                    echo "<tr>";
                                    echo "<th>Cnpj:</th><td>";
                                    echo "<input type='text' name='cnpj' size='30' value='". $usuario->getCnpj() . "'>";
                                    echo "</td></tr><tr>";
                                    echo "<th>Razão Social:</th><td>";
                                    echo "<input type='text' name='razaoSocial' size='70' value='". $usuario->getRazaoSocial() . "'>";
                                    echo "</td></tr><tr>
                                          <th>Foto:&nbsp;&nbsp;</th>
                                          <td><input type='file' id='foto' name='foto' size='15' onblur='comprova_extensao(this.form.foto.value)'>&nbsp;<label id='campo_foto'/><input type=hidden name=validacaoFoto id='validacaoFoto' value=1>
                                          <br><font size='1'>Formatos Permitidos </font><font color='red' size='1'>(JPEG,GIF,BMP,TIFF,PNG)</font>
                                          </td><td><img src='". $usuario->getFoto(). "' width='100' height='100' alt='Sem foto'/></td>
                                          </tr>";
                                }
                        }
                        echo "</td></tr><tr><td colspan='2' align='center'>";
                    }
                    ?>


                    <tr><td colspan="2" align="center">
                            <input id="Confirmar" type='Button'  value='Confirmar Edição' onclick="setAcao('formularioEdicaoUsuario', 'Atualizar')">
                        </td></tr>
                </table>
            </form>
             <script language="JavaScript">
                var cal1 = new calendar1(document.forms['formularioEdicaoUsuario'].elements['dataNascimento']);
                cal1.year_scroll = true;
                cal1.time_comp = false;
            </script>
        </center>
    </body>
</html>

